home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 December / CHIPNET Aralık 1997.iso / linux / redhat / misc / src / install / kernel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-11  |  2.1 KB  |  93 lines

  1. #include <errno.h>
  2. #include <fcntl.h>
  3. #include <newt.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6.  
  7. #include "fs.h"
  8. #include "install.h"
  9. #include "kernel.h"
  10. #include "log.h"
  11. #include "windows.h"
  12.  
  13. static int copyFile(char * sourceName, char * destName) {
  14.     int source, dest, i;
  15.     char buf[16384];
  16.     int olderrno;
  17.  
  18.     logMessage("coping %s to %s\n", sourceName, destName);
  19.  
  20.     source = open(sourceName, O_RDONLY);
  21.     if (source < 0) {
  22.     logMessage("file %s missing from source directory",
  23.             sourceName);
  24.     messageWindow("Error", "file %s missing from source directory",
  25.             sourceName);
  26.     return INST_ERROR;
  27.     }
  28.  
  29.     dest = creat(destName, 0644);
  30.     if (dest < 0) {
  31.     logMessage("failed to create file %s", destName);
  32.     messageWindow("Error", "failed to create file %s", destName);
  33.     close(source);
  34.     return INST_ERROR;
  35.     }
  36.  
  37.     while ((i = read(source, buf, sizeof(buf))) > 0) {
  38.     if (write(dest, buf, i) != i) {
  39.         olderrno = errno;
  40.  
  41.         logMessage("error writing to file %s: %s",
  42.                destName, strerror(olderrno));
  43.         messageWindow("Error", "error writing to file %s: %s",
  44.                destName, strerror(olderrno));
  45.  
  46.         close(source);
  47.         close(dest);
  48.         unlink(destName);
  49.         return 1;
  50.     }
  51.     }
  52.  
  53.     if (i < 0) {
  54.     olderrno = errno;
  55.  
  56.     logMessage("error reading from file %s: %s", sourceName, 
  57.             strerror(olderrno));
  58.     messageWindow("Error", "error reading from file %s: %s", sourceName, 
  59.             strerror(olderrno));
  60.     }
  61.  
  62.     close(source);
  63.     close(dest);
  64.     
  65.     if (i < 0)
  66.     return 1;
  67.  
  68.     return 0;
  69. }
  70.  
  71. int kernelCopy(char * filename) {
  72.     int rc = 0;
  73.  
  74.     if (!filename) {
  75.     messageWindow("Kernel", "Please insert your boot disk in your first "
  76.             "disk drive if it's not already present.");
  77.     if (doMount("fd0", "/tmp/bootdisk", "ext2", 1, 0))
  78.         return INST_ERROR;
  79.  
  80.     winStatus(34, 3, "Kernel", "Copying kernel from floppy...");
  81.     rc = copyFile("/tmp/bootdisk/vmlinux.gz", "/mnt/vmlinux.gz");
  82.     sync();
  83.     newtPopWindow();
  84.     } else {
  85.     winStatus(34, 3, "Kernel", "Copying kernel from floppy...");
  86.     rc = copyFile(filename, "/mnt/vmlinux.gz");
  87.     sync();
  88.     newtPopWindow();
  89.     }
  90.  
  91.     return rc;
  92. }
  93.